<!DOCTYPE html>
<html>
<!--
Copyright 2011 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
<title>Forwarding Handler Tests</title>
<script src="../third_party/closure/closure/goog/base.js"></script>
<script src="compat.js"></script>
<script src="forwarding_handler.js"></script>
<script>
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>

function getProxyAndObject() {
  var proto = {
    c: 'c',
    d: 'd',
  };
  var object = createObject({
    __proto__: proto,
    proto: proto,
    a: 'a',
    b: 'c',
  });
  return [object, Proxy.create(new ForwardingHandler(object))];
}

function testGetOwnPropertyDescriptor() {
  var [object, proxy] = getProxyAndObject();
  assertObjectEquals({
    'configurable': true,
    'enumerable': true,
    'value': 'a',
    'writable': true
  }, Object.getOwnPropertyDescriptor(object, 'a'));

  assertUndefined(Object.getOwnPropertyDescriptor(object, 'c'));
}

function testGetOwnPropertyNames() {
  var [object, proxy] = getProxyAndObject();
  assertArrayEquals(['proto', 'a', 'b'], // __proto__?
                    Object.getOwnPropertyNames(proxy));
}


function testDefineProperty() {
  var [object, proxy] = getProxyAndObject();
  Object.defineProperty(proxy, 'aa', {
    'configurable': false,
    'enumerable': false,
    'value': 'aa',
    'writable': false,
  });
  assertEquals('aa', object.aa);
  assertFalse(object.propertyIsEnumerable('aa'));
  assertFalse(delete object.aa);
  object.aa = 'change should be ignored';
  assertEquals('aa', object.aa);
}

function testDelete() {
  var [object, proxy] = getProxyAndObject();
  assertTrue(delete proxy.a);
  assertTrue(delete proxy.c);
  assertUndefined(proxy.a);
  assertFalse('a' in proxy);
  assertTrue('c' in proxy);
}

function testFix() {
  var [object, proxy] = getProxyAndObject();
  // TODO
}

function testHas() {
  var [object, proxy] = getProxyAndObject();
  assertTrue('a' in proxy);
  assertTrue('c' in proxy);
  assertFalse('q' in proxy);
}

function testHasOwn() {
  var [object, proxy] = getProxyAndObject();
  assertTrue(proxy.hasOwnProperty('a'));
  assertFalse(proxy.hasOwnProperty('c'));
}

function testGet() {
  var [object, proxy] = getProxyAndObject();
  assertEquals('a', proxy.a);
  assertEquals('c', proxy.c);
}

function testSet() {
  var [object, proxy] = getProxyAndObject();
  proxy.a = 'aa';
  proxy.c = 'cc';
  assertEquals('aa', object.a);
  assertEquals('cc', object.c);
}

function testEnumerate() {
  var [object, proxy] = getProxyAndObject();
}

function testKeys() {
  var [object, proxy] = getProxyAndObject();
  //assertArrayEquals(proxy.keys());
}

</script>
</body>
</html>
